package com.rr.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author RR
 * @date 2022/6/22 21:27
 */
@RestController
public class TestController {

    /*
    * 域名处变更为服务名（服务已注册到注册中心中）
    * nacos会根据服务名找到对应服务ip，并转发请求
    * http://nacosProvider/test/get
    * */
    @Value("${nacos-provider-url}")
    private String nacosProviderUrl;

    @Value("${nacos-provider-get-info-url}")
    private String nacosProviderGetInfoUrl;

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/test/get")
    public String testGetFromLoadBalance() {
        return restTemplate.getForObject(nacosProviderUrl, String.class);
    }

    @GetMapping("/test/getNacosInfo")
    public String testGetNacosInfoFromLoadBalance() {
        return restTemplate.getForObject(nacosProviderGetInfoUrl, String.class);
    }

}
